home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig07_07.jar
/
Ch07
/
Fig07_07
/
Fig07_07.cpp
next >
Wrap
C/C++ Source or Header
|
1997-10-20
|
570b
|
32 lines
// Fig. 7.7: fig07_07.cpp
// Using the this pointer to refer to object members.
#include <iostream.h>
class Test {
public:
Test( int = 0 ); // default constructor
void print() const;
private:
int x;
};
Test::Test( int a ) { x = a; } // constructor
void Test::print() const // ( ) around *this required
{
cout << " x = " << x
<< "\n this->x = " << this->x
<< "\n(*this).x = " << ( *this ).x << endl;
}
int main()
{
Test testObject( 12 );
testObject.print();
return 0;
}